package com.koron.css2.clientCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.NoticeBean;
import com.koron.css2.clientCenter.mapper.NoticeMapper;
import com.koron.css2.clientCenter.vo.NoticeDetailVo;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.HashMap;
import java.util.Map;

/**
 * 通知公告详情查询
 *
 * @author 杨嘉慧
 */
public class NoticeQuery implements ServerInterface {

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            NoticeBean notice = JsonUtils.objectToPojo(req.getData(), NoticeBean.class);
            NoticeMapper noticeMapper = factory.getMapper(NoticeMapper.class);
            Map<String, String> noticeMap = new HashMap<>();
            noticeMap.put("id", notice.getId());
            NoticeDetailVo noticeDetail = noticeMapper.noticeQuery(noticeMap);
            MessageBean<NoticeDetailVo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功",
                    NoticeDetailVo.class);
            info.setData(noticeDetail);
            return info;
        } catch (Exception e) {
            logger.error("通知公告详情查询失败" + e.getMessage(), e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "通知公告详情查询失败", null);
        }
    }

}
